///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.basecamp.wrappers
{

import summit.basecamp.constants.BasecampResource;
import summit.basecamp.helpers.TodoListHelper;
import summit.data.AccountToken;
import summit.net.BasecampLoader;

/**
 * Wrapper for Basecamp todo-list operations.
 */
public class TodoListWrapper extends AbstractWrapper implements 
IStandardWrapper, IListableWrapper, IParentWrapper
{
	/**
	 * @copy ProjectWrapper#ProjectWrapper()
	 */
	public function TodoListWrapper(token:AccountToken = null, 
	loader:BasecampLoader = null)
	{
		super(BasecampResource.TODOLIST, token, loader);
	}
	
	/** Gets an instance of a TodoItemWrapper. **/
	public function get child():IChildWrapper
	{
		return new TodoItemWrapper(null, loader);
	}
	
	/**
	 * Creates a todo-list.
	 * 
	 * <p>Typically, the XML provided is based on the template returned from
	 * a call to <code>prepare</code>.</p>
	 * 
	 * <p><code>project-id</code>, which represents the project that is 
	 * associated with the todo-list, is required.</p>
	 * 
	 * <p>Note: The new todo-list is always placed below all other existing 
	 * todo-lists (visually).</p>
	 * 
	 * @param content Represents the todo-list to be created.
	 * 
	 * @return A request ready for use with <code>BasecampLoader.load</code>.
	 */
	public function create(content:XML):void
	{
		loader.load(TodoListHelper.create(content));
	}
	
	/** Deletes an existing todo-list.
	 * 
	 * @param id The id of the todo-list to be deleted.
	 */
	public function destroy(id:String):void
	{
		loader.load(TodoListHelper.destroy(id));
	}
	
	/**
	 * Gets an existing todo-list from the Basecamp store.
	 * 
	 * <p>The XML returned is pre-filled with the existing values of 
	 * the identified todo-list, and is ready to be resubmitted via the 
	 * <code>update</code> function.</p>
	 * 
	 * @param id The id of the todo-list to be edited.
	 * @param projectId The id of the project associated with the todo-list.
	 * 
	 * @return A request ready for use with <code>BasecampLoader.load</code>.
	 */ 
	public function edit(id:String, projectId:String):void
	{
		loader.load(TodoListHelper.edit(id));
	}
	
	/**
	 * Gets a list of all todo-lists associated with the specified project.
	 * 
	 * @param projectId The id of the project from which todo-lists 
	 * are queried.
	 */
	public function list(projectId:String):void
	{
		loader.load(TodoListHelper.list(projectId));
	}
	
	/**
	 * Gets a list of todo-lists.
	 * 
	 * <p>If a <code>projectId</code> is given, the list of lists is scoped 
	 * to the specified project. In this case, <code>filter</code> can be used
	 * to further scope the lists.</p>
	 * 
	 * <p>If <code>projectId</code> is not provided, the query will span
	 * across all lists of all projects. If no <code>responsibleParty</code>
	 * is provided, the query will yield todo-lists with todo-items assigned
	 * to the requesting user.</p>
	 * 
	 * @param projectId The id of the project from which todo-lists 
	 * are queried. 
	 * @param filter Defines the query that determines which todo-lists to
	 * return. Possible values include:
	 * <ul>
	 *		<li><code>TodoListFilter.ALL</code>, the default, gets all 
	 * 		todo-lists for the project todo-items.</li>
	 *		
	 *		<li><code>TodoListFilter.PENDING</code> gets all todo-lists that 
	 * 		have todo-items that are NOT complete.</li>
	 * 
	 * 		<li><code>TodoListFilter.FINISHED</code> gets all todo-lists that 
	 * 		ONLY contain todo-items that are complete.</li>
	 * </ul>
	 * @param responsibleParty The id of the user or the company from which 
	 * todo-lists are queried. If no responsibleParty is provided (null), 
	 * todo-lists are returned for all users. If responsibleParty is provided 
	 * as an empty string (""), only unassigned items are returned. 
	 * If the responsibleParty is a company, the company id provided 
	 * should be preceeded with a "c", such as "c1234". 
	 * 
	 * @see summit.basecamp.constants.TodoListFilter
	 */
	public function listByFilter(projectId:String, filter:String = "all", 
	responsibleParty:String = null):void
	{
		loader.load(TodoListHelper.list(projectId, filter, responsibleParty));
	}
	
	/**
	 * Retrieves a single todo-list.
	 * 
	 * @param id The id of the todo-list to be read.
	 * @param projectId The id of the project associated with the todo-list.
	 */
	public function read(id:String, projectId:String):void
	{
		loader.load(TodoListHelper.read(id));
	}
	
	/**
	 * Reorders todo-lists.
	 * 
     * <p>Lists that only contain completed todo-items (eg completed lists) 
	 * can not be reordered.</p>
	 * 
	 * <p>Lists that are not referenced in <code>content</code> are reordered
	 * below the referenced todo-lists.</p>
	 * 
	 * @param content The list of todo-lists to be reordered. 
	 * @param projectId The id of the project associated with 
	 * the todo-lists. 
	 * 
	 */
	public function reorder(content:XML, projectId:String):void
	{
		loader.load(TodoListHelper.reorder(content, projectId));
	}
	
	/**
	 * Retrieves a template for creating a new todo-list.
	 * 
	 * <p>The template retrieved is used with <code>create</code> to 
	 * submit a new todo-list.</p>
	 * 
	 * @param projectId The id of the project that is to be associated with 
	 * the todo-list when submitted via a call to <code>create</code>.
	 */ 
	public function prepare(projectId:String):void
	{
		loader.load(TodoListHelper.prepare(projectId));
	}
	
	/**
	 * Updates an existing todo-list.
	 * 
	 * <p><code>content</code> submitted to <code>update</code> is typically
	 * retrieved from <code>edit</code>.</p>
	 * 
	 * @param content The updated XML content of an existing todo-list.
	 */ 
	public function update(content:XML):void
	{
		loader.load(TodoListHelper.update(content));
	}
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //